@extends('layouts.base')

@section('title', '公告')
@section('admin-style')
<link rel="stylesheet" href="{{ asset('assets\element-ui\lib\theme-chalk\index.css') }}">
<!-- import Vue before Element -->
<script src="{{ asset('assets\vue\vue.js')}}"></script>

<!-- import JavaScript -->
<script src="{{ asset('assets\element-ui\lib\index.js') }}"></script>
<script src="{{ asset('assets\axios\axios.min.js') }}"></script>
@stop
@section('content')

<!-- ============================================================== -->
<!-- Container fluid  -->
<!-- ============================================================== -->
<div class="container-fluid">
	<!-- ============================================================== -->
	<!-- Bread crumb and right sidebar toggle -->
	<!-- ============================================================== -->
	<div class="row page-titles">
	    <div class="col-md-5 align-self-center">
	        <h3 class="text-themecolor">公告--列表</h3>
	    </div>
	    <div class="col-md-7 align-self-center">
	        <ol class="breadcrumb">
	            <li class="breadcrumb-item"><a href="javascript:void(0)">首页</a></li>
	            <li class="breadcrumb-item">公告管理</li>
	            <li class="breadcrumb-item active">公告列表</li>
	        </ol>
	    </div>
	</div>
	<!-- ============================================================== -->
	<!-- End Bread crumb and right sidebar toggle -->
	<!-- ============================================================== -->
 
	<!-- ============================================================== -->
	<!-- Start Page Content -->
	<!-- ============================================================== -->
	<div class="row">
	    <div class="col-12">
	        <div class="card">
	            <div class="card-body">
	                <h4 class="card-title">管理列表</h4>
	                <h6 class="card-subtitle"></h6>
                	<div class="card-body">
                        {{-- <form method="get" action="{{ route('admin.managers.index') }}">
                            <div class="form-row">
                                <div class="col-md-3 mb-3">
                                  <label for="validationDefault04">姓名</label>
                                  <input type="text" name="name" class="form-control" id="validationDefault04" placeholder="姓名" value="{{ $name }}" >
                                </div>
                                <div class="col-md-3 mb-3">
                                  <label for="validationDefault05">手机号</label>
                                  <input type="text" name="phone" class="form-control" id="validationDefault05" placeholder="手机号" value="{{ $phone }}" >
                                </div>
                            </div>
                            <button class="btn btn-primary" type="submit">筛选</button>
                            <a href="{{ route('admin.managers.index') }}" class="btn btn-info">重置</a>
                        </form> --}}
                        @can('admin.notices.create')
                        <a class="btn btn-success float-right" href="{{ route('admin.notices.create') }}"><i class="fas fa-plus"></i> 添加</a>
                        @endcan       
                    </div>        
	                <div class="table-responsive">
	                    <table id="demo-foo-addrow" class="mail-desc table table-bordered m-t-30 table-hover contact-list" data-paging="true" data-paging-size="7">
	                        <thead>
	                            <tr>
	                            	<th>id</th>
	                                <th>标题</th>
	                                <th>内容</th>
	                                <th>公告发布对象类型</th>
	                                <th>创建时间</th>
	                                <th>操作</th>
	                            </tr>
	                        </thead>
	                        <tbody>
	                        	@foreach($notices as $value)
	                            <tr>
	                                <td>{{ $value->id }}</td>
	                                <td>{{ $value->title }}</td>
	                                <td>{{ $value->content }}</td>
	                                <td>{{ notice_type($value->type) }}</td>
	                                <td>{{ $value->created_at }}</td>
	                                <td>{!! $value->actionButton !!}</td>
	                            </tr>
	                            @endforeach
	                        </tbody>
	                    </table>
	                    {{ $notices->links() }}
	                </div>
	            </div>
	        </div>
	    </div>
	</div>
</div>         
                        
@stop

@section('admin-js')
	<script type="text/javascript">		

		Vue.prototype.$axios = axios;
	    Vue.prototype.$dcopy = function($arr){
	        return JSON.parse(JSON.stringify($arr));
	    }
	    new Vue({
	    	el: '#app',
            data(){
            	return {                  
                  nextActive:false,
              }
            },
            created(){

            },
            mounted(){
                
            },
            methods:{
            	publishNotice(id){
            		var that = this
            		swal({
					  title: "您确定要发布此消息吗?",
					  icon: "warning",
					  buttons: ['取消', '确定'],
					  dangerMode: true,
					})
					.then((willDelete) => {
					  if (willDelete) {			    
					    axios.get("{{ route('admin.notices.publishNotice') }}", {
	            			params:{'id':id}
	            		}).
	            		then(res => {
	            			if(res.data.code == 400){
					    		that.$message.error(res.data.message);
					    	}
					    	if(res.data.code == 200){
					    		that.$message.success(res.data.message);
					    	}
	            		});
					  }
					});            		
            	},
            	del(id){
            		var that = this;
            		swal({
					  title: "您确定要删除吗?",
					  icon: "warning",
					  buttons: ['取消', '确定'],
					  dangerMode: true,
					})
					.then((willDelete) => {
					  if (willDelete) {			    
					    axios.post("{{ route('admin.notices.delete') }}",{'id':id})
					    .then(res => {
					    	if(res.data.code == 400){
					    		that.$message.error(res.data.message);
					    	}
					    	if(res.data.code == 200){
					    		that.$message.success(res.data.message);
					    		location.href = "{{ route('admin.notices.index') }}"
					    	}
					    });
					  } else {
					    
					  }
					});
            	}
            }
	    });
		
	</script>

@stop